package Java测试.编码8;

//8 求1+2!+3!+...+20!的和？//结果为268040729
public class Test {
    public static void main(String[] args) {
//        int num=0;
//        for (int i = 1; i <=3; i++) {
//           num=sum(i);
//        }
        System.out.println("1!+2!+3!+……+20!="+(sum(1)+sum(2)+sum(3)+sum(4)+sum(5)+sum(6)
                +sum(7)+sum(8)+sum(9)+sum(10)+sum(11)+sum(12)+sum(13)
                +sum(14)+sum(15)+sum(16)+sum(17)+sum(18)+sum(19)+sum(20)));//结果为268040729
    }
    public static int sum(int i){
        if (i==1){
            return 1;
        }else{
            i=i*sum(i-1);
            return i;
        }
    }
}
